<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="vn.edu.hungvuongaptech.common.Constant"%>
<%@page import="vn.edu.hungvuongaptech.dao.ProjectDAO"%>
<%@page import="vn.edu.hungvuongaptech.dao.ProductDAO"%>
<%@page import="vn.edu.hungvuongaptech.dao.ProcessDAO"%>
<%@page import="vn.edu.hungvuongaptech.dao.WorkDAO"%>

<%@page import="vn.edu.hungvuongaptech.model.TimeSheetModel"%>
<%@page import="java.util.ArrayList"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="<%=request.getContextPath()%>/css/general.css" />
<link rel="stylesheet" href="<%=request.getContextPath()%>/css/aqua.css" />
<script type="text/javascript" src="<%=request.getContextPath()%>/js/General.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/zapatec.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/calendar.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/calendar-en.js"></script>
<title>Add TimeSheet Record Page</title>
<script language="JavaScript" type="text/javascript">
//Javascript validation functions
//http://www.designplace.org/

function isEmpty() {


//change "field1, field2 and field3" to your field names
strfield1 = document.frmAddTimeSheet.txtDate.value; 
strfield2 = document.frmAddTimeSheet.txtTime.value;
strfield3 = document.frmAddTimeSheet.txtDescription.value;

  //Date field
    if (strfield1 == "" || strfield1 == null || strfield1.charAt(0) == ' ')
    {
    alert("\"Date \" is a mandatory field.\nPlease fill and retry.");
    return false;
    }

  //Time field 
    if (strfield2 == "" || strfield2 == null || isNaN(parseFloat(strfield2)) || strfield2.charAt(0) == ' ')
    {
    alert("\"Time\" is a mandatory field.\nPlease fill and retry.");
    return false;
    }

  //Description field 
    if (strfield3 == "" || strfield3 == null || strfield3.charAt(0) == ' ')
    {
    alert("\"Description\" is a mandatory field.\nPlease fill and retry.");
    return false;
    }

    if(!IsNumeric(strfield2))
    return true;

 
} 

</script>
</head>
<body>
  <div id="main-wrap">
		<!-- S HEAD CONTENT -->
			<jsp:include page="../block/header.jsp" />
		<!-- E HEAD CONTENT -->
	
		<div class="space"></div>				
		<fmt:setBundle basename="i18n"/>
		
		<!-- S BODY CONTENT -->
		<div id="body">
			<div id="center-column">
				<form name="frmAddTimeSheet" action="AddTimeSheetController" method="post" onsubmit="return isEmpty()">
				<table cellpadding="4" align="center" border="0">
				  <tr>
				    <td colspan="7"><h2 align="center"><fmt:message key="timesheet.title.mainTitle" /></h2></td>
				  </tr>
				  <tr>				    
				    <td colspan="7" align="left">
				    	<p class="msg">
						   <c:if test='${not empty param.msg}'>
							   ${param.msg}
						   </c:if> </p>
				    	<p class="error_msg">
						   <c:if test='${not empty param.err}'>
							   ${param.err}
						   </c:if>
					     </p></td>				    
				  </tr>
				  <tr style="background-color: green">
				  	<th> <fmt:message key="timesheet.title.Date" /> </th>
				  	<th> <fmt:message key="timesheet.title.Time" /> </th>
				  	<th> <fmt:message key="timesheet.title.Description" /> </th>
				  	<th> <fmt:message key="timesheet.title.Project" /> </th>
				  	<th> <fmt:message key="timesheet.title.Proccess" /> </th>
				  	<th> <fmt:message key="timesheet.title.Work" /> </th>
				  	<th> <fmt:message key="timesheet.title.Product" /> </th>
				  </tr>				
				
				<c:choose>
					<c:when test='${not empty requestScope.TimeSheetRejectList}'>
						<c:set var="num" value='<%= ((ArrayList<TimeSheetModel>) request.getAttribute("TimeSheetRejectList")).size()%>'></c:set>
					</c:when>
					<c:otherwise>
						<c:set var="num" value='<%= Integer.parseInt(Constant.SETTING_RES.getString("ADD_TIMESHEETS.NUMBERS_OF_RECORDS"))%>'></c:set>						
					</c:otherwise>
				</c:choose>  				
				<c:forEach var="iterator" begin="1" end="${num}" step="1" >
				  <c:set var="RejectObj" value="${requestScope.TimeSheetRejectList[iterator-1]}"></c:set>
				  <tr>				  				   
				   <td><input type="text" name="txtDate${iterator}" id="txtDate${iterator}" size="10" value="${RejectObj.date}"  /> <img
								id="imgDate${iterator}" src="../images/view_calendar_day.png" alt="Calendar"
								height="20px" style="margin-bottom: -5px;" /></td>
				   <td style="width: 5px"><input name="txtTime${iterator}" id="txtTime${iterator}" type="text" width="5px" value="${RejectObj.time}"/></td>
				   <td><input type="text" id="txtDescription${iterator}" name="txtDescription${iterator}" value="${RejectObj.description}"/></td>				  				    			  
				   <td><select id="cboProject${iterator}" name="cboProject${iterator}">
							<c:set var="projectList" value="<%= ProjectDAO.getAllProject() %>" />
							<c:forEach items="${projectList}" var="item">
								<option value="${ item.projectId }" <c:if test="${item.projectId eq RejectObj.project.projectId}">selected</c:if>> ${ item.projectName } </option>
							</c:forEach>
						</select></td>
				   <td><select id="cboProcess${iterator}" name="cboProcess${iterator}">
							<c:set var="processList" value="<%= ProcessDAO.getAllProcess() %>" />
							<c:forEach items="${processList}" var="item">
								<option value="${ item.processId }" <c:if test="${item.processId eq RejectObj.process.processId}">selected</c:if>> ${ item.processName } </option>
							</c:forEach>
						</select></td>
				   <td><select id="cboWork${iterator}" name="cboWork${iterator}">
							<c:set var="workList" value="<%= WorkDAO.getAllWorks() %>" />
							<c:forEach items="${workList}" var="item">
								<option value="${ item.workId }" <c:if test="${item.workId eq RejectObj.work.workId}">selected</c:if>> ${ item.workName } </option>
							</c:forEach>
						</select></td>				  
				   <td><select id="cboProduct${iterator}" name="cboProduct${iterator}">
							<c:set var="productList" value="<%= ProductDAO.getAllProducts() %>" />
							<c:forEach items="${productList}" var="item">
								<option value="${ item.productId }" <c:if test="${item.productId eq RejectObj.product.productId}">selected</c:if>> ${ item.productName } </option>
							</c:forEach>
						</select></td>				  				   				  				   				  				    				  				    
				  </tr>
				  </c:forEach>
				  <tr>				    
				    <td colspan="7" align="center"><input name="btnSubmit" id="btnSubmit" type="submit" value='<fmt:message key="timesheet.button.Submit" />'/></input>&nbsp;&nbsp;
				        <input name="btnReset" id="btnReset" type="reset" value='<fmt:message key="timesheet.button.Reset" />'/>
				    </td>
				  </tr>
				</table>
<script type="text/javascript">
//<![CDATA[  
  <%
  	int numRow = 0;
  	if (request.getAttribute("TimeSheetRejectList") == null) {
  		numRow = Integer.parseInt(Constant.SETTING_RES.getString("ADD_TIMESHEETS.NUMBERS_OF_RECORDS"));
  	} else {
  		numRow = ((ArrayList<TimeSheetModel>) request.getAttribute("TimeSheetRejectList")).size();
  	}
  	for(int i=1; i<= numRow ; i++) {
  		String output = "";
  		output += "Zapatec.Calendar.setup({";
  		output += "firstDay          : 1,";
  		output += "weekNumbers       : false,";
  		output += "range             : [2010.01, 2020.12],";
  		output += "electric          : false,";
  		output += "inputField        : 'txtDate" + i + "',";
  		output += "button            : 'imgDate" + i + "',";
  		output += "ifFormat          : '%m-%d-%Y'";
  		output += "});";
  		
  		out.println(output);
  	}
  	
  %>
//]]>
</script>
				</form>
			</div>
		</div>
		<!-- E BODY CONTENT -->
	
		<div class="space"></div>
		
		<!-- S FOOT CONTENT -->
			<jsp:include page="../block/footer.jsp" />
		<!-- E FOOT CONTENT -->
	</div>

</body>
</html>